const dataValue = (valueKey: string) => ({
  get({ data }: any) {
    return data[valueKey]
  },
  set({ data }: any, value: string) {
    data[valueKey] = value
  }
})
const numberValue = (valueKey: string) => ({
  get({ data }: any) {
    return String(data[valueKey] || 0)
  },
  set({ data }: any, value: string) {
    data[valueKey] = Number(value) || 0
  }
})
const jsonValue = (valueKey: string) => ({
  get({ data }: any) {
    return JSON.stringify(data[valueKey] || {}, null, '  ')
  },
  set({ data }: any, value: string) {
    data[valueKey] = JSON.parse(value || '{}')
  }
})
export default {
  '@init'({ style }) {
    style.width = '100%'
    style.height = '100%'
  },
  '@resize': {
    options: ['width', 'height']
  },
  ':root': {
    items: [
      {
        title: '地图样式',
        type: 'Select',
        options: [
          { value: 'normal', label: '标准(normal)' },
          { value: 'dark', label: '幻影黑(dark)' },
          { value: 'light', label: '月光银(light)' },
          { value: 'whitesmoke', label: '远山黛(whitesmoke)' },
          { value: 'fresh', label: '草色青(fresh)' },
          { value: 'grey', label: '雅士灰(grey)' },
          { value: 'graffiti', label: '涂鸦(graffiti)' },
          { value: 'macaron', label: '马卡龙(macaron)' },
          { value: 'blue', label: '靛青蓝(blue)' },
          { value: 'darkblue', label: '极夜蓝(darkblue)' },
          { value: 'wine', label: '酱籽(wine)' }
        ],
        value: dataValue('mapStyle')
      },
      {
        title: '地图中心',
        items: [
          {
            title: '经度(lng)',
            type: 'text',
            options: [{ min: 0, max: 1000, width: 180 }],
            value: numberValue('lng')
          },
          {
            title: '纬度(lng)',
            type: 'text',
            options: [{ min: 0, max: 1000, width: 180 }],
            value: numberValue('lat')
          }
        ]
      },
      {
        title: '信息窗体',
        type: 'style',
        options: {
          defaultOpen: true,
          plugins: ['border', 'font', 'bgcolor', 'padding', 'shadow']
        },
        value: dataValue('infoWndStyle')
      }
    ]
  }
}
